package com.finance.system.support.bean;

import com.finance.system.support.utils.RequestUtils;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class GlobalResponse<T> {
    private String errorCode;
    private String errorMsg;
    private String requestId;
    private boolean success = false;
    private T data;

    public static <T> GlobalResponse<T> success(T data){
        GlobalResponse<T> response = new GlobalResponse<>();
        response.setSuccess(true);
        response.setData(data);
        response.setRequestId(RequestUtils.getRequestId());
        return response;
    }

    public static <T> GlobalResponse<T> fail(String errorMsg,String errorCode){
        GlobalResponse<T> response = new GlobalResponse<>();
        response.setSuccess(false);
        response.setErrorMsg(errorMsg);
        response.setErrorCode(errorCode);
        response.setRequestId(RequestUtils.getRequestId());
        return response;
    }
}

